package controlador;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 * 
 * @author Juanvi y Oscar
 *
 */
public class RendererJLabel extends JLabel implements TableCellRenderer{

	DefaultTableCellRenderer renderer;//Declaracion de un renderer
	
	/**
	 * Constructor de la clase
	 * 
	 * @param tabla JTable - tabla del que se va a obtener el renderer
	 */
	public RendererJLabel(JTable tabla) {
		renderer = (DefaultTableCellRenderer)tabla.getTableHeader().getDefaultRenderer();//Asigna el renderer de la tabla a la variable renderer
		renderer.setHorizontalAlignment(this.CENTER);//Centra horizontalmente
		setOpaque(true);
	}

	@Override
	public Component getTableCellRendererComponent(JTable tabla, Object valor,
			boolean arg2, boolean arg3, int arg4, int arg5) {		
		if(valor.getClass() == String.class){
			if(valor.equals("falta")){
				setBackground(Color.RED);
			}else{
				setBackground(Color.WHITE);
				setText("NO");
			}
			if(valor.equals("retraso")){
				setBackground(Color.YELLOW);
			}	
			if(valor.equals("faltaRetraso")){
				setBackground(Color.ORANGE);
			}
		}	
		return this;
	}
}
